package com.demo.component;

import com.demo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author sehun
 * @description
 * @date 2024/5/22
 */
@Component
public class UserBeans {
    @Bean
    // 设置作用域的两种方法
//    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) // 1 全局变量的方法设置
    @Scope("prototype") // 2 直接设置值
    public User user() {
        User user = new User();
        user.setId(1);
        user.setName("sehun");
        user.setAge(31);
        return user;
    }
}














